home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / TGCBOR20.ARJ / INTROPAK.COM / MENUDEMO.C < prev    next >
Text File  |  1991-05-29  |  16KB  |  422 lines

  1. /* comprehensive menu demo */
  2.  
  3.  
  4. #include "teglsys.h"
  5. /*
  6. #include <teglcond.h>
  7. #include <dos.h>
  8. #include <stdlib.h>
  9. #include <tgraph.h>
  10. #include <fastgrph.h>
  11. #include <teglintr.h>
  12. #include <fontsys.h>
  13. #include <virtmem.h>
  14. #include <ipstacks.h>
  15. #include <teglunit.h>
  16. #include <teglmain.h>
  17. #include <errorlog.h>
  18. #include <teglmenu.h>
  19. */
  20.  
  21. unsigned beeptimes = 3;
  22. unsigned dropclick = 0;
  23. unsigned char booleanclick1 = TRUE;
  24. unsigned char booleanclick2 = FALSE;
  25. unsigned char booleanclick3 = FALSE;
  26.  
  27. unsigned exitoption(imagestkptr fs,msclickptr ms)
  28. {
  29.     abortexit("Menu keys test");
  30.     return 1;
  31. }
  32.  
  33. /*
  34.  * This event is only added by the AddEntry event. When clicked on, this
  35.  * event drops its own option menu entry from the menu.
  36.  */
  37.  
  38. unsigned deleteentry(imagestkptr fs,msclickptr ms)
  39. {
  40.     optionmptr om;
  41.  
  42.     /* returns the related Option Menu chain */
  43.     om = getfsom(fs);
  44.  
  45.     /*
  46.      * Drops the current option entry, using the ms^.clicknumber as the entry
  47.      * number
  48.      */
  49.     dropoptionentry(om,ms->clicknumber);
  50.  
  51.     return 1;
  52. }
  53.  
  54. /*
  55.  * AddEntries demonstrates how you can retrieve the current Option Menu and
  56.  * its related Option entry and insert another option entry into the current
  57.  * option menu.
  58.  */
  59.  
  60. unsigned addentries(imagestkptr fs,msclickptr ms)
  61. {
  62.     optionmptr om;
  63.  
  64.     /* returns the related Option Menu chain */
  65.     om = getfsom(fs);
  66.  
  67.     /*
  68.      * sets the Option entry position in preparation of inserting another
  69.      * entry. If the option entry number is 0, DefineOptions will create an
  70.      * entry at the beginning of the chain.
  71.      */
  72.     setcurrentoepos(om,ms->clicknumber - 1);
  73.  
  74.     /*
  75.      * use the standard DefineOptions() DefineOptionsRadio()
  76.      * DefineOptionsCheck() or DefineOptionsSub() to create a new entry
  77.      */
  78.  
  79.     defineoptions(om,"~D~elete Entry ",TRUE,deleteentry);
  80.     return 1;
  81. }
  82.  
  83.  
  84. /*
  85.  * You can change the action of the menu bar to drop down menus in which the
  86.  * menu drops with a passing of the mouse. "dropclick" is an automatic
  87.  * variable which is by the menu routines before calling this event. The
  88.  * value in the "dropclick" is either 0 or 1 as passed by the
  89.  * DefineOptionsRadio() below.
  90.  */
  91.  
  92.  
  93. unsigned dropclicktoggle(imagestkptr fs,msclickptr ms)
  94. {
  95.     /*
  96.      * resets the complete mouseclick chain stored in a FS to MSClick or
  97.      * MSSense. MSClick is a boolean value of 0, and MSSense is 1.
  98.      */
  99.     resetmsclicksense(fs->relatedstack,dropclick);
  100.  
  101.     return 1;
  102. }
  103.  
  104.  
  105. /*
  106.  * Acknowledge is a simple event that aknowledges that it has been called by
  107.  * beeping. The number of beeps is controlled by the variable Beeptimes;
  108.  * which is an automatic variable updated by the menu routines. For more info
  109.  * on automatic variables, look at the menu defines for DefineOptionsRadio().
  110.  */
  111.  
  112. unsigned acknowledge(imagestkptr fs,msclickptr ms)
  113. {
  114.     unsigned i;
  115.  
  116.     /*
  117.      * Use WaitforUserRelease to wait for the user to release either the key
  118.      * or mouse button before proceeding. Waiting for the user to release the
  119.      * mouse button is not necessary in a menu since the menu waits for you
  120.      * to release before calling the event. However if you use the same event
  121.      * for icons or other defined mouse click areas, this event may be called
  122.      * several times before the button is release.
  123.      */
  124.  
  125.     waitforuserrelease();
  126.  
  127.     for (i = 1; i <= beeptimes; i++) {
  128.     beep(1000,1,150);
  129.     beep(500,1,50);
  130.     }
  131.     return 1;
  132. }
  133.  
  134.  
  135. /*
  136.  * Defining the option menus may be defined within a procedure or at the MAIN
  137.  * part of the program.
  138.  */
  139.  
  140.  
  141. void createmenubarevents(void)
  142. {
  143.     optionmptr om1,om2,om3,om4,om5;
  144.  
  145.     /*
  146.      * StandardFont is set with the initialization of TEGL in Fastgrph. When
  147.      * creating Option menus, the proportional flag is saved with each option
  148.      * menu, therefore if you wish to have non-proportional menus, you must
  149.      * set the proportional flag off before creating the option menu.
  150.      */
  151.  
  152.     setproportional(TRUE);
  153.  
  154.     /*
  155.      * OM1 is a standard menu with each entry attached to the Acknowledge
  156.      * event. The dashed line is used to indicate a line separator between
  157.      * topics.
  158.      */
  159.  
  160.     standardfont = roman25;
  161.  
  162.     om1 = createoptionmenu(standardfont);
  163.     defineoptions(om1,"DeskTop Info...",TRUE,acknowledge);
  164.     defineoptions(om1,"--",FALSE,NULL);
  165.     defineoptions(om1,"Calculator",TRUE,acknowledge);
  166.     defineoptions(om1,"Clock",TRUE,acknowledge);
  167.     defineoptions(om1,"Snapshot",TRUE,acknowledge);
  168.  
  169.  
  170.     /*
  171.      * OM2 uses a combination of several features offered in TEGLMENU. The
  172.      * first is the ">" symbol in Open. This symbol tells the option menu
  173.      * (when listing) to right justify the remaining portion of the text.
  174.      *
  175.      * The curly brackets around F1^ will display F1^ in tiny font.
  176.      *
  177.      * The tilde ~ character indicates the underscoring of the enclosed
  178.      * characters, of which the first character becomes the default keyboard
  179.      * activator.
  180.      *
  181.      * Global key clicks like Alt-x and ctrl-F1 must be defined using the
  182.      * definelocal and defineglobal key clicks. The menu routine only
  183.      * recognizes alphabets and numeric characters when attaching local key
  184.      * clicks.
  185.      */
  186.  
  187.     om2 = createoptionmenu(standardfont);
  188.     defineoptions(om2,"Open >{ctrl-F1}",TRUE,acknowledge);
  189.     defineoptions(om2,"Show ~I~nfo...",FALSE,acknowledge);
  190.     defineoptions(om2,"--",FALSE,NULL);
  191.     defineoptions(om2,"~N~ew Folder...",FALSE,acknowledge);
  192.     defineoptions(om2,"~C~lose",FALSE,acknowledge);
  193.     defineoptions(om2,"Close ~W~indow",FALSE,acknowledge);
  194.     defineoptions(om2,"--",FALSE,NULL);
  195.     defineoptions(om2,"~F~ormat...",TRUE,acknowledge);
  196.     defineoptions(om2,"To ~O~utput",TRUE,acknowledge);
  197.     defineoptions(om2,"{ALT-X}~Q~uit",TRUE,exitoption);
  198.     defineglobalkeyclickarea(NULL,NULL,0x082d,FALSE,exitoption);
  199.     defineglobalkeyclickarea(NULL,NULL,0x003b,FALSE,acknowledge);
  200.  
  201.     /*
  202.      * DefineOptionsRadio provides a method of toggling between options or
  203.      * group of options. The controlling variable is updated automatically by
  204.      * the menu handler before the your event is called. You can use
  205.      * "NULL" if you don't need any other activity after the user has
  206.      * toggle the appropriate menu choices.
  207.      *
  208.      * The parameters 1,2,3,4 in DefineOptionsRadio is the value that is used to
  209.      * compare against the variable BeepTimes in determing whether or not the
  210.      * entry is prefixed with a check mark. When defining radio entries, be
  211.      * sure to set the menu margins to 10 or more pixels to allow room for
  212.      * the check mark symbol.
  213.      */
  214.  
  215.     setmenumargin(10);
  216.     om3 = createoptionmenu(standardfont);
  217.     defineoptionsradio(om3,"~C~lick Menus",TRUE,dropclicktoggle,0,&dropclick);
  218.     defineoptionsradio(om3,"~D~rop Menus",TRUE,dropclicktoggle,1,&dropclick);
  219.     defineoptions(om3,"-",FALSE,NULL);
  220.  
  221.     defineoptionscheck(om3,"~A~-Check Menus",TRUE,NULL,&booleanclick1);
  222.     defineoptionscheck(om3,"~B~-Check Menus",TRUE,NULL,&booleanclick2);
  223.     defineoptionscheck(om3,"~C~-Check Menus",TRUE,NULL,&booleanclick3);
  224.  
  225.     defineoptions(om3,"-",FALSE,NULL);
  226.     defineoptionscheck(om3,"~S~ound On",TRUE,acknowledge,&beepstatus);
  227.  
  228.     defineoptions(om3,"-",FALSE,NULL);
  229.     defineoptionsradio(om3,"Beep ~1~ time ",TRUE,acknowledge,1,&beeptimes);
  230.     defineoptionsradio(om3,"Beep ~2~ times",TRUE,acknowledge,2,&beeptimes);
  231.     defineoptionsradio(om3,"Beep ~3~ times",FALSE,acknowledge,3,&beeptimes);
  232.     defineoptionsradio(om3,"Beep ~4~ times",TRUE,acknowledge,4,&beeptimes);
  233.  
  234.  
  235.     /*
  236.      * Two other unique features of TEGLMENU is used in this option menu. The
  237.      * Addentries event is added as a menu entry, which when activated,
  238.      * inserts another option entry above the current entry. The inserted
  239.      * entry is a delete option entry, which when activated, will delete
  240.      * itself from the option menu. Refer to the events above to see how this
  241.      * is done... The Delete entry at the bottom of the menu demonstrates
  242.      * that even the last entry can be deleted.
  243.      *
  244.      * The defineoptionsSub() is introduced here, allowing the linking of
  245.      * several option menus including itself for a recursive chaining of
  246.      * menus. Again watch for the menumargins. A margin must be provided on
  247.      * the right side for displaying the submenu symbol (). In the example
  248.      * below, the largest entry is longer than the defineoptionsSub entry,
  249.      * thereby allowing us to use a menu margin of 5 without the submenu
  250.      * symbol overlapping with our option entry text.
  251.      */
  252.  
  253.     setmenumargin(5);
  254.     om4 = createoptionmenu(standardfont);
  255.     defineoptions(om4,"~A~dd More Entries ",TRUE,addentries);
  256.     defineoptions(om4,"Chance ~I~nfo...",TRUE,acknowledge);
  257.     defineoptions(om4,"~F~rame Test Write...",TRUE,acknowledge);
  258.     defineoptions(om4,"~C~redit Option.",TRUE,acknowledge);
  259.     defineoptions(om4,"~D~os Shell...",TRUE,acknowledge);
  260.     defineoptionssub(om4,"~S~ort Options",TRUE,om3);
  261.     defineoptionssub(om4,"More ~O~ptions",TRUE,om2);
  262.     defineoptionssub(om4,"~R~ecursive",TRUE,om4);
  263.     defineoptions(om4,"--",FALSE,NULL);
  264.     defineoptions(om4,"Select Nothing...",TRUE,acknowledge);
  265.     defineoptions(om4,"Show Memory...",TRUE,acknowledge);
  266.     defineoptions(om4,"Show ~B~utton Status",TRUE,acknowledge);
  267.     defineoptions(om4,"Set ~M~ouse Sensivity",TRUE,acknowledge);
  268.     defineoptions(om4,"--",FALSE,NULL);
  269.     defineoptions(om4,"~A~dd More Entries ",TRUE,addentries);
  270.     defineoptions(om4,"Delete ~E~ntry ",TRUE,deleteentry);
  271.  
  272.     /*
  273.      * TEGL automatically converts menus to menus with sliders when the
  274.      * number of entries displayed is greater than the screen size. You can
  275.      * adjust the display number to a smaller size
  276.      */
  277.  
  278.     setomdisplaynum(om4,15);
  279.  
  280.     /*
  281.      * The last option menu demonstrates the ability to create long menu
  282.      * entries. The current maximum is set to 40 characters per menu entry.
  283.      * You can change this by changing the constant MaxTextStringSize which
  284.      * is defined at the top of the TEGLMENU module.
  285.      *
  286.      * Notice the use of the | character in |Types |Variables |Attributes and
  287.      * |Objects.  This is the tab expansion character allowing simple
  288.      * formating on the menu.
  289.      */
  290.  
  291.  
  292.     om5 = createoptionmenu(standardfont);
  293.     defineoptions(om5,"~S~tandard Unit Dependencies",TRUE,acknowledge);
  294.     defineoptions(om5,"The System Unit",TRUE,acknowledge);
  295.     defineoptions(om5,"The Printer Unit",TRUE,acknowledge);
  296.     defineoptions(om5,"--",FALSE,NULL);
  297.     defineoptions(om5,"The Dos Unit",TRUE,acknowledge);
  298.     defineoptions(om5,"Constants |Types |Variables",TRUE,acknowledge);
  299.     defineoptions(om5,"Methods |Attributes |Objects",TRUE,acknowledge);
  300.     defineoptions(om5,"File |Streams |TEGL",TRUE,acknowledge);
  301.     defineoptions(om5,"~A~dd More Entries ",TRUE,addentries);
  302.     defineoptions(om5,"--",FALSE,NULL);
  303.     defineoptions(om5,"Interrupt Support Procedures",TRUE,acknowledge);
  304.     defineoptions(om5,"Disk Status Functions",TRUE,acknowledge);
  305.     defineoptions(om5,"File-Handling Procedures and functions",TRUE,acknowledge);
  306.  
  307.     setteglfont(standardfont);
  308.     createbarmenu(0,0,getmaxx());
  309.     setbarmenumargin(24);
  310.     outbaroption(" ~D~esk  ",om1);
  311.     setmousebutton(stackptr->msptr,2);
  312.     outbaroption(" ~F~ile  ",om2);
  313.     outbaroption(" ~V~iew  ",om3);
  314.     outbaroption(" A ~S~econd Chance ",om4);
  315.     outbaroption(" Standard ~U~nits ",om5);
  316.     outbarevent(" ~B~eep ",acknowledge);
  317.     resetmsclicksense(stackptr,dropclick);
  318.  
  319.  
  320.     /* Define the ESC key to simulate a function key for escaping from menus */
  321.     defineglobalkeyclickarea(stackptr,NULL,0x0001,FALSE,NULL);
  322.  
  323.     /* If you don't need it later, you can use the following to drop the ESC */
  324.     /* DropKeyClick(NIL,$0001,NULL);                  */
  325. }
  326.  
  327.  
  328.  
  329. void main()
  330. {
  331. /*  Easier Startup */
  332.     easytegl();
  333.  
  334. /*  Optional Startup. Forcing a Video Mode */
  335. /*  Note: Use either easytegl() or teglinit(). NOT both */
  336. /*
  337.     registertgidriver(GRVGA256_driver);
  338.     setstandardheapsize(20000l); /* Reserve about 20k for Video Drivers */
  339.     teglinit("SVGA1024x768x256",12288l);
  340.     clearteglscreen();
  341. */
  342.     seteasyfont(font14);
  343.     easyout();
  344.  
  345.     setrgbpalette(240,0,0,0);
  346.     setrgbpalette(255,63,63,63);
  347.  
  348.     /*
  349.      * There are a number of variables that are used to control the visual
  350.      * aspects of the menus. The MC table stores the setup values for the
  351.      * menu in which you can create a similar table with your default values
  352.      * and simply assign the whole table to MC.
  353.      *
  354.      * As an example, a HERC_MC table has been created for your in TEGLMENU.  If
  355.      * you are using a Hercules monitor you can use the following statement
  356.      * to set your menu defaults immediately.
  357.      *
  358.      * IF Getmaxcolor < 2 then    (* set B/W parms *) MC := HERC_MC;
  359.      *
  360.      * If you only need to set a few default parameters, here is a quick summary
  361.      * of the functions that are available that you may use to control your
  362.      * menu displays....
  363.      *
  364.      * SetOptionMenuColors(activecolor,inactivecolor:unsigned); ... Sets the
  365.      * active and inactive text entry colors within the menu. The default
  366.      * colors is set to Black and lightgray respectively.
  367.      *
  368.      * SetOptionMenuBorderColor(Color:unsigned); ... Sets the Border color
  369.      * around the menu. The default border color is black.
  370.      *
  371.      * SetBarTextColor(Color:unsigned); ... Sets the text color on the bar menu.
  372.      * Default is Black.
  373.      *
  374.      * SetBarMenuMargin(margin:unsigned); ... Sets the left margin on the Bar
  375.      * menu. Useful if you wish to display an icon at the upper left corner
  376.      * of the bar menu. The default is an indentation of 16 pixels from the
  377.      * left part of the bar menu.
  378.      *
  379.      * SetBarMenuColor(Color:unsigned); ... Sets the Bar menu Color. Default is
  380.      * white.
  381.      *
  382.      * SetBarBorderOff; ... Sets the Border off. Default is on.
  383.      *
  384.      * SetBarBorderColor(Color:unsigned); ... Sets the Bar Border color and
  385.      * turns the border on. Default is black.
  386.      *
  387.      * SetHideSubMenu(on_off:Boolean); ... You can choose whether to hide the
  388.      * option menu after the user makes a selection. The default is the menu
  389.      * remains shown until the event completes its task and returns.
  390.      *
  391.      * SetMenuMargin(pixsize:unsigned); ... Sets the option menu margin. The
  392.      * default is 10 pixels before the option entry text. A minimum of 10
  393.      * pixels is needed for check mark option entries.
  394.      *
  395.      * SetMenuTabsize(charnum:unsigned); ... Sets the number of characters for
  396.      * tab expansion. A tab is represented by the | character. The default is
  397.      * 8 characters.
  398.      *
  399.      * SetSeparatorLine(mask:unsigned); ... Sets the mask for the line
  400.      * separator. A dotted line is $EE and a solidline is $FF. The default is
  401.      * a solidline.
  402.      *
  403.      * SetInactiveJaggies(on_off:Boolean); ... Inactive option entries may be
  404.      * displayed with jagged characters. The default is off.
  405.      *
  406.      * SetOMSliderSize(width,height:unsigned); ... Sets the width and height of
  407.      * the slider buttons. Minimum button size is 9x9
  408.      */
  409.  
  410.  
  411.     setomslidersize(15,12);
  412.     sethidesubmenu(FALSE);
  413.     setmenutabsize(12);
  414.     /* SetSeparatorLine($EE); *//* creates dashed separator lines */
  415.     createmenubarevents();
  416.  
  417.     /* Sets the ctrlbreak key to the exit event */
  418.     setctrlbreakfs(exitoption);
  419.  
  420.     teglsupervisor();
  421. }
  422.